#include "Nodes.h"

node::node(int _r, int _x, int _y, SpideyWindow * parent)      // default: _x = 0, _y = 0
{
    x = _x;
    y = _y;
    r = _r;
    move(x, y);
    if(parent) {
        parent -> scene -> addItem(this);
    }
}

void node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
            QWidget *widget)
{
    painter -> setBrush(Qt::black);
	painter -> drawEllipse(-r, -r, (r * 2), (r * 2));
}

QRectF node::boundingRect() const
{
    return QRectF(-r, -r, 2*r, 2*r);
}

void node::move(int x, int y)
{
    setPos(x, y);
}

void node::moveBy(int _x, int _y)
{
    setPos(x + _x, y + _y);
}

void node::addToWindow(SpideyWindow *newWindow)
{
    if(newWindow) {
        newWindow->scene->addItem(this);
    }
}

void node::addToScene(QGraphicsScene *newScene)
{
    if(newScene) {
        newScene->addItem(this);
    }

}
